﻿<Window
    x:Class="Srk.BetaseriesApiApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
    xmlns:vm="clr-namespace:Srk.BetaseriesApiApp.ViewModels"
    xmlns:ctrls="clr-namespace:Srk.BetaseriesApiApp.Controls"
    xmlns:conv="clr-namespace:Srk.BetaseriesApiApp.Converters"
    Title="Betaseries WPF Demo" Height="600" Width="680"
    x:Name="me">
    <Window.Resources>
        <conv:PasswordParameterConverter x:Key="PasswordParameterConverter" />
        <conv:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter" />
        <conv:BoolToColorConverter x:Key="BoolToColorConverter" />
        <conv:ImplementedVerifiedConverter x:Key="ImplementedVerifiedConverter" />
        <!--<CollectionViewSource x:Key="MethodsCvs" Source="{Binding MethodsCV}" />-->

        <conv:VersionListViewItemStyleSelector x:Key="VersionListViewItemStyleSelector" />
        <conv:BadgeListViewItemStyleSelector x:Key="BadgeListViewItemStyleSelector" />
        
        <DataTemplate x:Key="BoolGridViewColumnWithColors">
            <TextBlock Text="{Binding}" Foreground="{Binding Converter={StaticResource BoolToColorConverter}}" Background="Gray" />
        </DataTemplate>

        <Style TargetType="{x:Type ListViewItem}" x:Key="ListViewItemStyleBase">
            <!--<Setter Property="BorderThickness" Value="0,0,0,1" />-->
            <Setter Property="BorderThickness" Value="1" />
            <!--<Setter Property="BorderBrush" Value="LightGray" />-->
            <Setter Property="BorderBrush" Value="LightGray" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                        <Border Background="{TemplateBinding Background}"
								BorderBrush="{TemplateBinding BorderBrush}"
								BorderThickness="{TemplateBinding BorderThickness}"
								Padding="{TemplateBinding Padding}">
                            <StackPanel>
                                <GridViewRowPresenter />
                            </StackPanel>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="true">
                	<Setter Property="Foreground" Value="Black" />
                	<Setter Property="BorderBrush" Value="Navy" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type ListViewItem}" x:Key="EpisodeListViewItemStyle">
            <!--<Setter Property="BorderThickness" Value="0,0,0,1" />-->
            <Setter Property="BorderThickness" Value="1" />
            <!--<Setter Property="BorderBrush" Value="LightGray" />-->
            <Setter Property="BorderBrush" Value="LightGray" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                        <Border Background="{TemplateBinding Background}"
								BorderBrush="{TemplateBinding BorderBrush}"
								BorderThickness="{TemplateBinding BorderThickness}"
								Padding="{TemplateBinding Padding}">
                            <StackPanel Orientation="Vertical">
                                <GridViewRowPresenter />
                                <TextBlock Text="{Binding Description}" TextWrapping="Wrap"
                                           x:Name="tb" Visibility="Collapsed" HorizontalAlignment="Stretch" />
                            </StackPanel>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                            	<Setter Property="Visibility" Value="Visible" TargetName="tb" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="true">
                        <!--<Setter Property="Background" Value="Navy" />
                        <Setter Property="Foreground" Value="White" />-->
                	<Setter Property="Foreground" Value="Black" />
                	<Setter Property="BorderBrush" Value="Navy" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_NotImplemented">
            <Setter Property="Background" Value="LightGray" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_UpToDate">
            <Setter Property="Background" Value="LightGreen" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_Outdated">
            <Setter Property="Background" Value="LightSalmon" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_Green">
            <Setter Property="Background" Value="LightGreen" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_Yellow">
            <Setter Property="Background" Value="Yellow" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_Orange">
            <Setter Property="Background" Value="Orange" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_Red">
            <Setter Property="Background" Value="LightSalmon" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_Gray">
            <Setter Property="Background" Value="LightGray" />
        </Style>

        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyleBase}" 
               x:Key="ListViewItemStyle_Blue">
            <Setter Property="Background" Value="LightBlue" />
        </Style>
        
                <!--<Setter.Value>
                    <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                        <GradientStop Color="" />
                    </LinearGradientBrush>
                </Setter.Value>-->
        
    </Window.Resources>
    <Window.DataContext>
        <vm:Main />
    </Window.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Expander DataContext="{Binding Login}">
            <Expander.Header>
                <Grid>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock xml:space="preserve"><Run Text="Auth // "/></TextBlock>
                        <TextBlock Text="{Binding StatusMessage}" />
                        <TextBlock Text="{Binding ErrorMessage}" 
                                   Foreground="Red"
                                   Visibility="{Binding ErrorMessage, Converter={StaticResource NotNullToVisibilityConverter}}"/>
                    </StackPanel>
                </Grid>
            </Expander.Header>
            <TabControl x:Name="tcAccount" Margin="4,0,4,12">
                <TabItem Header="Login / Logout">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Label Grid.Row="1" Grid.Column="0" xml:space="preserve" Content="Username: "/>
                        <TextBox Grid.Row="1" Grid.Column="1" 
                                 Text="{Binding Username}"
                                 IsEnabled="{Binding IsNotBusy}" />
                        <CheckBox Grid.Row="1" Grid.Column="2" IsChecked="{Binding SaveUsername}" Content="Save"/>

                        <Label Grid.Row="2" Grid.Column="0" xml:space="preserve" Content="Password: "/>
                        <PasswordBox Grid.Row="2" Grid.Column="1"
                                     x:Name="pwLogin"
                                     IsEnabled="{Binding IsNotBusy}" />
                        <CheckBox Grid.Row="2" Grid.Column="2" IsChecked="{Binding SavePassword}" Content="Save"/>
                    
                        <Button Grid.Row="3" Grid.Column="0"
                                Click="LoginButton_Click"
                                IsEnabled="{Binding CanLoginProp}" Content="Login"/>

                        <Button Grid.Row="3" Grid.Column="1"
                                Command="{Binding LogoffCommand}" Content="Logout"/>

                    </Grid>
                </TabItem>
                <TabItem Header="Account informations">
                    <Grid DataContext="{Binding CurrentMember}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="8" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                    
                        <Border Grid.Row="0" Grid.Column="0" Grid.RowSpan="5"
                                HorizontalAlignment="Center" VerticalAlignment="Center"
                                Margin="8" Background="LightGray"
                                BorderThickness="5" CornerRadius="4">
                            <Border.BorderBrush>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                    <GradientStop Offset="0" Color="Blue" />
                                    <GradientStop Offset="0.5" Color="LightGray" />
                                    <GradientStop Offset="1" Color="Green" />
                                </LinearGradientBrush>
                            </Border.BorderBrush>
                            <Image Source="{Binding PictureUrl}" Width="100" Height="128"/>
                        </Border>
                    
                        <Label Grid.Row="0" Grid.Column="1" xml:space="preserve" Content="Username: "/>
                        <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding Username}" />

                        <Label Grid.Row="1" Grid.Column="1" xml:space="preserve" Content="Shows: "/>
                        <TextBlock Grid.Row="1" Grid.Column="2" Text="{Binding ShowCount}" />

                        <Label Grid.Row="2" Grid.Column="1" xml:space="preserve" Content="Seasons: "/>
                        <TextBlock Grid.Row="2" Grid.Column="2" Text="{Binding SeasonCount}" />

                        <Label Grid.Row="3" Grid.Column="1" xml:space="preserve" Content="Episodes: "/>
                        <TextBlock Grid.Row="3" Grid.Column="2" Text="{Binding EpisodeCount}" />

                        <Label Grid.Row="0" Grid.Column="4" xml:space="preserve" Content="Progress: "/>
                        <TextBlock Grid.Row="0" Grid.Column="5" Text="{Binding Progress}" />

                        <Label Grid.Row="1" Grid.Column="4" xml:space="preserve" Content="Episodes remaining: "/>
                        <TextBlock Grid.Row="1" Grid.Column="5" Text="{Binding EpisodesToWatchCount}" />

                        <Label Grid.Row="2" Grid.Column="4" xml:space="preserve" Content="Time spent: "/>
                        <TextBlock Grid.Row="2" Grid.Column="5" Text="{Binding TimeSpent}" />

                        <Label Grid.Row="3" Grid.Column="4" xml:space="preserve" Content="Time remaining: "/>
                        <TextBlock Grid.Row="3" Grid.Column="5" Text="{Binding TimeRemaining}" />
                        <!--
                    
                        <Label Grid.Row="" Grid.Column="1" xml:space="preserve">XXXXXX: </Label>
                        <TextBlock Grid.Row="" Grid.Column="2" Text="{Binding YYYYYYYY}" />
                        -->
                    </Grid>
                </TabItem>
                <TabItem Header="Badges" DataContext="{Binding DataContext.UserBadges, ElementName=me}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        
                        <StackPanel Orientation="Horizontal">
                            <TextBox Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}" Width="180" Margin="4" />
                            <Button Content="Go" Command="{Binding GetBadgesCommand}" Margin="4" />
                            <TextBlock Text="{Binding StatusMessage}" Margin="4" />
                        </StackPanel>
                        
                        <ListView Grid.Row="2" ItemsSource="{Binding Badges}" Height="220">
                            <ListView.View>
                                <GridView>
                                    <GridViewColumn Header="Svc Key" DisplayMemberBinding="{Binding ServiceName}" />
                                    <GridViewColumn Header="Lib Key" DisplayMemberBinding="{Binding InternalType}" />
                                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding TranslatedName}" />
                                    <GridViewColumn Header="Description" DisplayMemberBinding="{Binding TranslatedDescription}" />
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </Grid>
                </TabItem>
                <TabItem Header="Friends" DataContext="{Binding DataContext.Friends, ElementName=me}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <StackPanel Orientation="Horizontal">
                            <TextBox Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}" Width="180" Margin="4" />
                            <Button Content="Go" Command="{Binding GetFriendsCommand}" Margin="4" />
                            <Button Content="Stop" Command="{Binding StopCommand}" Margin="4" />
                            <TextBlock Text="{Binding StatusMessage}" Margin="4">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MouseLeftButtonUp">
                                        <cmd:EventToCommand Command="{Binding ShowErrorsCommand}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </TextBlock>
                        </StackPanel>

                        <ListView Grid.Row="2" ItemsSource="{Binding Members}" Height="220">
                            <ListView.View>
                                <GridView>
                                    <GridViewColumn Header="Username" DisplayMemberBinding="{Binding Username}" />
                                    <GridViewColumn Header="Shows" DisplayMemberBinding="{Binding ShowCount}" />
                                    <GridViewColumn Header="Seasons" DisplayMemberBinding="{Binding SeasonCount}" />
                                    <GridViewColumn Header="Episodes" DisplayMemberBinding="{Binding EpisodeCount}" />
                                    <GridViewColumn Header="EpisodesToWatch" DisplayMemberBinding="{Binding EpisodesToWatchCount}" />
                                    <GridViewColumn Header="TimeSpent" DisplayMemberBinding="{Binding TimeSpent}" />
                                    <GridViewColumn Header="TimeRemaining" DisplayMemberBinding="{Binding TimeRemaining}" />
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </Grid>
                </TabItem>
            </TabControl>
        </Expander>
        
        <TabControl x:Name="tcMain" Grid.Row="2">
            <TabControl.Background>
                <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                    <GradientStop Color="LightGray" Offset="0" />
                    <GradientStop Color="White" Offset=".01" />
                    <GradientStop Color="#ffC7D5EA" Offset="1" />
                </LinearGradientBrush>
            </TabControl.Background>
            <TabItem Header="Search shows" x:Name="tabSearch" DataContext="{Binding ShowsSearch}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <WrapPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
                        <TextBox Text="{Binding SearchString, UpdateSourceTrigger=PropertyChanged}"
                                 Width="240" Margin="8,4,8,4" />
                        <Button Command="{Binding SearchCommand}"
                                IsDefault="True" Margin="8,4,8,4" Content="Go"/>
                    </WrapPanel>

                    <WrapPanel Grid.Row="0" Grid.Column="1"/>

                    <ListView Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Margin="4"
                              ItemsSource="{Binding Shows}" x:Name="lvSearchShows"
                              SelectedItem="{Binding SelectedShow}"
                              MouseDoubleClick="shows_MouseDoubleClick"
                              ScrollViewer.CanContentScroll="True">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Title}" />
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Episodes" x:Name="showMenu_Episodes" Click="showMenu_Episodes_Click" />
                                <MenuItem Header="Comments" x:Name="showMenu_Comments" Click="showMenu_Comments_Click" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                    
                    <!--<GridSplitter Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="4"
                                  ResizeDirection="Rows"
                                  Height="4" HorizontalAlignment="Stretch"
                                  Background="Gray" />-->

                    <ctrls:ShowControl DataContext="{Binding SelectedShow}"
                                       Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="4" />
                    
                    <TextBlock Grid.Row="4" Grid.ColumnSpan="2" Text="{Binding StatusMessage}" Margin="4" />
                </Grid>
            </TabItem>
            <TabItem Header="Show" DataContext="{Binding ShowInfo}" x:Name="tabInfo">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <ctrls:ShowControl DataContext="{Binding Show}"
                                       Grid.Row="0" Margin="4" />

                    <ListView Grid.Row="2" Margin="4" x:Name="lvEpisodes"
                              ItemsSource="{Binding Show.Episodes}"
                              ScrollViewer.CanContentScroll="True"
                              ItemContainerStyle="{StaticResource EpisodeListViewItemStyle}">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Number" DisplayMemberBinding="{Binding Number}" />
                                <GridViewColumn Header="S" DisplayMemberBinding="{Binding SeasonOrder}" />
                                <GridViewColumn Header="E" DisplayMemberBinding="{Binding Order}" />
                                <GridViewColumn Header="Date" DisplayMemberBinding="{Binding Date}" />
                                <GridViewColumn Header="Rating" DisplayMemberBinding="{Binding Rating}" />
                                <GridViewColumn Header="Title" DisplayMemberBinding="{Binding Title}" />
                                <GridViewColumn Header="Seen" DisplayMemberBinding="{Binding IsSeen}" />
                                <GridViewColumn Header="Downloaded" DisplayMemberBinding="{Binding IsDownloaded}" />
                            </GridView>
                        </ListView.View>
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Comments" x:Name="episodeMenu_Comments" Click="episodeMenu_Comments_Click" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>

                    <TextBlock Grid.Row="3" Text="{Binding StatusMessage}" Margin="4" />
                </Grid>
            </TabItem>
            <TabItem Header="Version" DataContext="{Binding Version}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <WrapPanel Grid.Row="0" Orientation="Horizontal">
                        <Button Command="{Binding MethodsCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Update"/>
                        <Button Command="{Binding CopyTracCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Copy for trac"/>
                        <Button Command="{Binding SaveCsvCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Save as CSV"/>
                    </WrapPanel>

                    <WrapPanel Grid.Row="1" Orientation="Horizontal">
                        <CheckBox Content="Implemented" IsThreeState="True"
                                  IsChecked="{Binding FilterImplemented}" Margin="8,4,8,4" />
                        <CheckBox Content="Up-to-date" IsThreeState="True"
                                  IsChecked="{Binding FilterUptodate}" Margin="8,4,8,4" />
                    </WrapPanel>

                    <ListView Grid.Row="2" Margin="4"
                              ItemsSource="{Binding MethodsCV}"
                              ItemContainerStyleSelector="{StaticResource VersionListViewItemStyleSelector}">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Method" 
                                                DisplayMemberBinding="{Binding Name}" />
                                <GridViewColumn Header="Implemented?" 
                                                DisplayMemberBinding="{Binding IsImplemented}"
                                                CellTemplate="{StaticResource BoolGridViewColumnWithColors}" />
                                <GridViewColumn Header="Last" 
                                                DisplayMemberBinding="{Binding Last}" />
                                <GridViewColumn Header="Current" 
                                                DisplayMemberBinding="{Binding Current}" />
                                <GridViewColumn Header="Up-to-date" 
                                                DisplayMemberBinding="{Binding IsUpToDate}"
                                                CellTemplate="{StaticResource BoolGridViewColumnWithColors}"  />
                            </GridView>
                        </ListView.View>
                    </ListView>

                    <TextBlock Grid.Row="3" Text="{Binding StatusMessage}" Margin="4" />
                </Grid>
            </TabItem>
            <TabItem Header="Badges" DataContext="{Binding Badges}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    
                    <TextBlock Margin="4" TextWrapping="Wrap" FontSize="10"><Run Text="The API does not provide direct access to badges. Clicking the Update button will fetch the global website timeline trying to find new badge keys. All found badge keys will be saved. You are supposed to click update at different times to find new badges or to use automatic update (10 minutes interval)."/></TextBlock>

                    <WrapPanel Grid.Row="1" Orientation="Horizontal">
                        <ToggleButton IsChecked="{Binding IsAutoUpdateEnabled}" 
                                      Margin="4" Content="Auto update"/>
                        <Button Command="{Binding UpdateCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Update"/>
                        <Button Command="{Binding UpdateSelfCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Update from my profile"/>
                        <Button Command="{Binding UpdateFriendsCommand}" 
                                HorizontalAlignment="Left" Margin="4" Content="Update from friends"/>
                        <Button Command="{Binding UpdateUserCommand}" 
                                HorizontalAlignment="Left" Margin="4">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock xml:space="preserve"><Run Text="Update from user "/></TextBlock>
                                <TextBox Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}" 
                                         Width="80" FontSize="8" IsEnabled="{Binding IsNotBusy}" />
                            </StackPanel>
                        </Button>
                    </WrapPanel>

                    <WrapPanel Grid.Row="2" Orientation="Horizontal">
                        <CheckBox Content="Verified" IsThreeState="True"
                                  IsChecked="{Binding FilterVerified}" Margin="8,4,4,4" />
                        <CheckBox Content="Implemented" IsThreeState="True"
                                  IsChecked="{Binding FilterImplemented}" Margin="8,4,4,4" />
                        <CheckBox Content="Name translated" IsThreeState="True"
                                  IsChecked="{Binding FilterNameTranslated}" Margin="8,4,4,4" />
                        <CheckBox Content="Description translated" IsThreeState="True"
                                  IsChecked="{Binding FilterDescriptionTranslated}" Margin="8,4,4,4" />
                        <CheckBox Content="Require attention" IsThreeState="True"
                                  IsChecked="{Binding FilterRequireAttention}" Margin="8,4,4,4" />
                    </WrapPanel>

                    <ListView Grid.Row="3" Margin="4"
                              ItemsSource="{Binding BadgesCV}"
                              ItemContainerStyleSelector="{StaticResource BadgeListViewItemStyleSelector}">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="ServiceName" 
                                                DisplayMemberBinding="{Binding ServiceName}" />
                                <GridViewColumn Header="InternalType" 
                                                DisplayMemberBinding="{Binding InternalType}" />
                                <GridViewColumn Header="Implementation" 
                                                DisplayMemberBinding="{Binding Converter={StaticResource ImplementedVerifiedConverter}}"
                                                CellTemplate="{StaticResource BoolGridViewColumnWithColors}" />
                                <GridViewColumn Header="TranslatedName" 
                                                DisplayMemberBinding="{Binding TranslatedName}" />
                                <GridViewColumn Header="TranslatedDescription" 
                                                DisplayMemberBinding="{Binding TranslatedDescription}" />
                            </GridView>
                        </ListView.View>
                    </ListView>
                    
                    <GridSplitter Grid.Row="4" ResizeBehavior="PreviousAndNext" ResizeDirection="Auto" Height="4" Background="Gray" HorizontalAlignment="Stretch" />
                    
                    <Grid Grid.Row="5">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        
                        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="2"
                                    HorizontalAlignment="Right" VerticalAlignment="Top" Panel.ZIndex="10">
                            <!--<TextBlock Margin="4,4,16,4">Log</TextBlock>-->
                            <TextBox Text="{Binding LogSearch, UpdateSourceTrigger=PropertyChanged}" Width="240" Margin="4" />
                            <Button Content="Clear" Command="{Binding ClearLogCommand}" Margin="4,4,32,4" />
                        </StackPanel>
                        
                        <ScrollViewer Grid.Row="1" Margin="2">
                            <ItemsControl ItemsSource="{Binding LogCV}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border BorderBrush="Gray" BorderThickness="0,0,0,1">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="{Binding Date}" VerticalAlignment="Center" Margin="4" />
                                                <ItemsControl ItemsSource="{Binding Entries}">
                                                    <ItemsControl.ItemTemplate>
                                                        <DataTemplate>
                                                            <StackPanel Orientation="Horizontal">
                                                                <TextBlock FontWeight="Bold" Text="{Binding Key}" Margin="2" />
                                                                <ItemsControl ItemsSource="{Binding Value}">
                                                                    <ItemsControl.ItemsPanel>
                                                                        <ItemsPanelTemplate>
                                                                            <WrapPanel Orientation="Horizontal" />
                                                                        </ItemsPanelTemplate>
                                                                    </ItemsControl.ItemsPanel>
                                                                    <ItemsControl.ItemTemplate>
                                                                        <DataTemplate>
                                                                            <TextBlock Text="{Binding}" Margin="2,2,8,2" />
                                                                        </DataTemplate>
                                                                    </ItemsControl.ItemTemplate>
                                                                </ItemsControl>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ItemsControl.ItemTemplate>
                                                </ItemsControl>
                                            </StackPanel>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ScrollViewer>
                    </Grid>

                    <ItemsControl Grid.Row="6" Margin="4"
                                  ItemsSource="{Binding Stats}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="Gray" BorderThickness="1" Padding="4" Margin="2,2,4,2">
                                    <Border.Background>
                                        <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                                            <GradientStop Color="LightGray" Offset="0" />
                                            <GradientStop Color="White" Offset=".1" />
                                            <GradientStop Color="#ffC7D5EA" Offset="1" />
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <TextBlock Text="{Binding}" />
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock Grid.Row="7" Text="{Binding StatusMessage}" Margin="4" />
                </Grid>
            </TabItem>
            <TabItem Header="Timelines">
                <TabControl>
                    <TabItem Header="Main">
                        <ctrls:TimelineControl DataContext="{Binding MainTimeline}" />
                    </TabItem>
                    <TabItem Header="Own">
                        <ctrls:TimelineControl DataContext="{Binding OwnTimeline}" />
                    </TabItem>
                    <TabItem Header="Friends">
                        <ctrls:TimelineControl DataContext="{Binding FriendsTimeline}" />
                    </TabItem>
                </TabControl>
            </TabItem>
            <TabItem Header="Comments" x:Name="tabComments" DataContext="{Binding EpisodesComments}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="60" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="60" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    
                    <TextBlock Text="Show: " Grid.Row="0" Grid.Column="0" Margin="0,4,8,2" HorizontalAlignment="Right" />
                    <TextBlock Text="Season: " Grid.Row="1" Grid.Column="0" Margin="0,4,8,2" HorizontalAlignment="Right" />
                    <TextBlock Text="Episode: " Grid.Row="1" Grid.Column="2" Margin="0,4,8,2" HorizontalAlignment="Right" />
                    <TextBlock Text="Member: " Grid.Row="2" Grid.Column="0" Margin="0,4,8,2" HorizontalAlignment="Right" />
                    <!--<TextBlock Text="Write a comment: " Grid.Row="3" Grid.Column="0" Margin="0,4,8,2" HorizontalAlignment="Right" />-->
                    
                    <TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" Margin="4"
                             Text="{Binding MyShow, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="4"
                             Text="{Binding MySeason, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBox Grid.Row="1" Grid.Column="3" Margin="4"
                             Text="{Binding MyEpisodeNB, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Margin="4"
                             Text="{Binding MemberLogin, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Grid.RowSpan="2" Margin="4"
                             AcceptsReturn="True" VerticalScrollBarVisibility="Visible"
                             Text="{Binding Comment, UpdateSourceTrigger=PropertyChanged}" />
                    
                    <!--<TextBlock Margin="7.706,8,1.097,8" Grid.Row="3" TextWrapping="Wrap" Text="Member"/>
                    <TextBox Grid.ColumnSpan="3" Grid.Column="1" Margin="8" Grid.Row="3" TextWrapping="Wrap" Text="{Binding MemberLogin}"/>
                    <Button Content="Fetch member comments" Grid.Column="4" Margin="8" Grid.Row="3" RenderTransformOrigin="0.516,0.484" Command="{Binding GetMemberCommentsCommand}"/>-->

                    <Button Grid.Column="4" Grid.Row="0" Margin="4" Content="Fetch show comments"
                            Command="{Binding SearchShowCommentCommand}" />
                    <Button Grid.Column="4" Grid.Row="1" Margin="4" Content="Fetch episode comments"
                            Command="{Binding SearchCommand}" />
                    <Button Grid.Column="4" Grid.Row="2" Margin="4" Content="Fetch member comments"
                            Command="{Binding GetMemberCommentsCommand}" />
                    <Button Grid.Row="3" Grid.Column="4" Margin="4" Content="Comment on show"
                            Command="{Binding CommentShowCommand}" />
                    <Button Grid.Row="4" Grid.Column="4" Margin="4" Content="Comment on episode"
                            Command="{Binding CommentEpisodeCommand}" />
                    <Button Grid.Row="5" Grid.Column="4" Margin="4" Content="Comment on member"
                            Command="{Binding CommentMemberCommand}" />
                    
                    <StackPanel Grid.Row="5" Grid.ColumnSpan="4" Orientation="Horizontal">
                        <TextBlock xml:space="preserve"><Run Text="Comment in reply to comment: "/></TextBlock>
                        <TextBlock Text="{Binding SelectedComment.InnerId, FallbackValue=None, TargetNullValue=None}" />
                        <Button Content="x" Command="{Binding ClearReplyCommand}" Margin="4,0" Padding="2,0" Height="16" FontSize="8" />
                    </StackPanel>

                    <ListView Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6" Margin="8"
                              ItemsSource="{Binding MyComments}"
                              SelectedItem="{Binding SelectedComment, Mode=OneWayToSource}"
                              x:Name="lvComments">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Posted date"
                                                DisplayMemberBinding="{Binding Postdate}" />
                                <GridViewColumn Header="ID"
                                                DisplayMemberBinding="{Binding InnerId}" />
                                <GridViewColumn Header="Reply"
                                                DisplayMemberBinding="{Binding InreplyTo}" />
                                <GridViewColumn Header="Posted by"
                                                DisplayMemberBinding="{Binding Username}" />
                                <GridViewColumn Header="Comment"
                                                DisplayMemberBinding="{Binding Text}" />
                            </GridView>
                        </ListView.View>
                    </ListView>

                    <TextBlock Grid.Row="7" Grid.ColumnSpan="6" Text="{Binding StatusMessage}" Margin="4" />
                </Grid>
            </TabItem>
            <TabItem Header="Site news" x:Name="tabSitenews" DataContext="{Binding SiteNews}">
                
            </TabItem>
            <TabItem Header="Query" DataContext="{Binding Query}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Loaded">
                        <cmd:EventToCommand Command="{Binding LoadedCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="QueryCol1" Width="Auto" />
                        <ColumnDefinition SharedSizeGroup="QueryCol2" />
                    </Grid.ColumnDefinitions>
                    
                    <TextBlock Text="Action: " />
                    <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Action}" />

                    <CheckBox Grid.Row="1" Content="Key" IsChecked="{Binding IsKeyEnabled}" />
                    <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Key}" IsEnabled="False" />

                    <CheckBox Grid.Row="2" Content="Token" IsChecked="{Binding IsTokenEnabled}" />
                    <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Token}" IsEnabled="False" />

                    <ItemsControl Grid.Row="4" Grid.ColumnSpan="2"
                                  ItemsSource="{Binding Arguments}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition SharedSizeGroup="QueryCol1" Width="Auto" />
                                        <ColumnDefinition SharedSizeGroup="QueryCol2" />
                                    </Grid.ColumnDefinitions>

                                    <CheckBox IsChecked="{Binding IsEnabled}">
                                        <TextBox Text="{Binding Key}" />
                                    </CheckBox>
                                    <TextBox Grid.Column="1" Text="{Binding Value}" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <Button Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Right" VerticalAlignment="Top"
                            Content="+" Command="{Binding NewArgCommand}" />

                    <StackPanel Grid.Row="5" Grid.ColumnSpan="2" Orientation="Horizontal">
                        <Button Content="Execute" Command="{Binding ExecuteCommand}" />
                        <Button Content="Save" />
                    </StackPanel>

                    <TextBox Grid.Row="6" Grid.ColumnSpan="2" Text="{Binding QueryString}" IsReadOnly="True" />
                    
                    <TextBox Grid.Row="7" Grid.ColumnSpan="2" Text="{Binding Response}"
                             AcceptsReturn="True" AcceptsTab="True" />

                    <TextBlock Grid.Row="8" Grid.ColumnSpan="2" Text="{Binding StatusMessage}" Margin="4" />
                </Grid>
            </TabItem>
            <TabItem Header="Debug" DataContext="{Binding Debug}">
                <StackPanel>
                    <Button Command="{Binding BreakCommand}" HorizontalAlignment="Left" Content="Breakpoint"/>
                </StackPanel>
            </TabItem>
        </TabControl>
        
    </Grid>
</Window>
